package com.atguigu.a_test;

import java.util.HashMap;
import java.util.Map;
import java.util.Set;

/*
    双列集合嵌套双列集合
        外层集合 -> 学校 -> <班级名称,班级集合> -> HashMap<String,HashMap<String,Student>>
        内层集合 -> 班级集合 -> <学号,学生对象> -> HashMap<String,Student>
 */
public class Demo2 {
    public static void main(String[] args) {
        //创建班级集合
        HashMap<String, Student> basic = new HashMap<>();
        basic.put("basic001",new Student("张三",18));
        basic.put("basic002",new Student("李四",18));
        basic.put("basic003",new Student("王五",18));
        HashMap<String, Student> job = new HashMap<>();
        job.put("job001",new Student("赵六",18));
        job.put("job002",new Student("田七",18));
        job.put("job003",new Student("朱八",18));

        //创建学校集合
        HashMap<String, HashMap<String, Student>> school = new HashMap<>();
        school.put("基础班",basic);
        school.put("就业班",job);

        //外层 : keySet
        Set<String> classNames = school.keySet();
        for (String className : classNames) {
            //键找值
            HashMap<String, Student> clazz = school.get(className);
            //内层 : entrySet
            Set<Map.Entry<String, Student>> entries = clazz.entrySet();
            for (Map.Entry<String, Student> entry : entries) {
                String sid = entry.getKey();
                Student student = entry.getValue();
                //获取学生信息
                String name = student.getName();
                int age = student.getAge();
                System.out.println("班级名称 : " + className + " , 学生学号 : " + sid + " , 学生姓名 : " + name + " , 学生年龄 : " + age);
            }
        }
    }
}
